//
// C++ Implementation: mainactivitywidget
//
// Description:
//
//
// Author: Willi Ballenthin <wilbal1087@gmail.com>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "mainactivitywidget.h"


MainActivityWidget::MainActivityWidget ( QSqlDatabase* db, QWidget *parent )
        : QWidget ( parent )
{
    query      = new ActivityDbInterface ( db );
    query->setFilter ( "WHERE type='Run'" );
    QVector<Activity>* vector = query->query();

    vbl_main   = new QVBoxLayout(this);
    viewWidget = new ActivityViewWidget ( vector, this );
    editWidget = new ActivityEditWidget( db, this);
    editWidget->setObjectName(QString::fromUtf8("editWidget"));
    editWidget->setGeometry(QRect(10, 250, 480, 200));

    setObjectName(QString::fromUtf8("Main Activity Widget"));
    setGeometry(QRect(0, 25, 585, 840));
    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);

    vbl_main->addWidget(viewWidget);
    vbl_main->addWidget(editWidget);

    show();

    editWidget->setDisabled(true);

    // HACK:
    connect ( viewWidget, SIGNAL ( needEdit ( Activity* ) ), editWidget, SLOT ( edit ( Activity* ) ) );
    /* no need to re-query the db on each update if we have an updated model
    *  TODO: when should the database be queried for an updated model?
    *  ideally only on startup.
    */
    connect ( editWidget, SIGNAL (updatedModel()), query, SIGNAL(updatedModel()));
    connect ( query, SIGNAL ( updatedModel (  ) ), viewWidget, SLOT ( updateView ()));
    // only called on a new model/new query
    connect ( query, SIGNAL ( newModel ( QVector< Activity >* ) ), viewWidget, SLOT ( setActivities ( QVector< Activity >* ) ) );
}


MainActivityWidget::~MainActivityWidget()
{
}


